package com.itheima.stream;

import java.util.*;
import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        //方式1，单列集合，调用collection接口的默认stream()方法
        // method1();
        //方式2，双列集合，通过keySet()或者entrysSet()方法获取set集合对象，再调用collection接口的默认stream()方法
        //method2();
        //方式3，数组，通过Arrays.stream
        //method3();
        //方式4，同类型的多个数据，通过Stream.of(T... values)来接受多个参数，并通过Arrays.Stream封装到数组
        method4();
    }

    private static void method4() {
        int a=1;
        int b=2;
        int c=3;
        //T... values
        Stream.of(a,b,c).forEach(s-> System.out.println(s));
    }

    private static void method3() {
        int[] a=new int[]{2,1,3,4,5};
        Arrays.stream(a).forEach(s-> System.out.println(s));
    }

    private static void method2() {
        TreeMap<String, String> tm = new TreeMap<>(Map.ofEntries(Map.entry("yy","24"),Map.entry("yyds","18")));
        Set<Map.Entry<String, String>> entries = tm.entrySet();
        entries.stream().forEach((en)->{
            System.out.println(en.getKey()+en.getValue());
        });
        Set<String> set = tm.keySet();
        set.stream().forEach((s1) -> System.out.println(s1+tm.get(s1)));
    }

    private static void method1() {
        ArrayList<String> list = new ArrayList<>(List.of("a","b","c","d","e"));
        list.stream().forEach(s -> System.out.println(s));
    }
}
